package com.larry.isn;

public class Recorder {

	private Integer totalSum = 0;

	private Integer runSum = 0;

	private Integer callBackSum = 0;

	private Integer concurents = 0;

	public Recorder(Integer concurents) {
		this.concurents = concurents;
	}

	public synchronized void runSum() {
		runSum++;
		totalSum++;
	}

	public synchronized void callback() {
		callBackSum++;
		if (callBackSum.intValue() >= concurents.intValue()) {
			this.init();
		}
	}

	public synchronized Boolean isAllowToNextTurn() {
		if (runSum.intValue() <= concurents.intValue()) {
			return true;
		}
		if (callBackSum.intValue() >= concurents.intValue()) {
			return true;
		}
		return false;
	}

	public synchronized void init() {
		runSum = 0;
		callBackSum = 0;
	}

	public synchronized Integer getRunSum() {
		return runSum;
	}

	public synchronized Integer getCallBackSum() {
		return callBackSum;
	}

	public synchronized Integer getTotalSum() {
		return totalSum;
	}
}
